import 'package:flutter/material.dart';
import 'package:state_flutter/components/Dialog/dialog.dart';

import 'package:state_flutter/components/Swiper/swiper.dart';
import 'package:state_flutter/components/NavBar/navbar.dart';

class IndexPage extends StatefulWidget {
  IndexPage({Key key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: NavBar({
        'leading': true,
        'title': 'IndexPage'
      }),
      body: IndexBody(),
    );
  }
}

/*
 * IndexBody  Index页面内容
 */
class IndexBody extends StatefulWidget {
  IndexBody({Key key}) : super(key: key);

  @override
  _IndexBodyState createState() => _IndexBodyState();
}

class _IndexBodyState extends State<IndexBody> {
  
  Map swiper = {
    'autoplay': true,
    'duration': 800,
    'list': [
      {'id': 0, 'url': 'https://c-ssl.duitang.com/uploads/item/201711/26/20171126195857_MtFYk.thumb.700_0.jpeg'},
      {'id': 1, 'url': 'https://c-ssl.duitang.com/uploads/item/201711/26/20171126195857_MtFYk.thumb.700_0.jpeg'},
      {'id': 2, 'url': 'https://c-ssl.duitang.com/uploads/item/201711/26/20171126195857_MtFYk.thumb.700_0.jpeg'},
    ]
  };

  _modelBottomSheet() async{
    var res = await showModalBottomSheet(
      context: context,
      builder: (context){
        return Container(
          height: 200.0,
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text('分享 A'),
                onTap: (){
                  Navigator.pop(context, 'A');
                },
              ),
              ListTile(
                title: Text('分享 B'),
                onTap: (){
                  Navigator.pop(context, 'B');
                },
              ),
              ListTile(
                title: Text('分享 C'),
                onTap: (){
                  Navigator.pop(context, 'C');
                },
              ),
            ],
          ),
        );
      }
    );
    print(res);
  }

  
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          width: double.infinity,
          padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
          child: AspectRatio(
            aspectRatio: 16/9,
            child: SwiperConstructor(this.swiper),
          ),
        ),
        Wrap(
          children: <Widget>[
            RaisedButton(
              child: Text('go to Card'),
              onPressed: (){
                Navigator.pushNamed(context, '/card');
              },
              color: Colors.blue,
              textColor: Colors.white,
            ),
            SizedBox(width: 10,),
            FlatButton(
              child: Text('open sheet'),
              onPressed: (){
                _modelBottomSheet();
              },
              color: Colors.blue,
              textColor: Colors.white,
            ),
            SizedBox(width: 10,),
            FlatButton(
              child: Text('自定义 Dialog'),
              color: Colors.blue,
              textColor: Colors.white,
              onPressed: (){
                showDialog(
                  context: context,
                  builder: (context){
                    return DialogConstructor();
                  }
                );
              },
            )
          ],
        )
      ],
    );
  }
}
